package com.opencart.web.propertyEditor;

import java.beans.PropertyEditorSupport;

import com.opencart.service.CategoryService;

public class CategoryEditor extends PropertyEditorSupport {
	private CategoryService categoryService;

	public CategoryEditor(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		if (text != null && !text.isEmpty()) {
			Long id = Long.parseLong(text);
			setValue(this.categoryService.findById(id));
		} else {
			setValue(null);
		}

	}

}
